using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace Presentation
{
    public partial class frmTimKiemKhachThue : Form
    {
        int flag = 0;
        public frmTimKiemKhachThue()
        {
            InitializeComponent();
        }

        private void rdbThongThuon_Click(object sender, EventArgs e)
        {
            flag = 1;
            lblTenKT.Visible = false;
            lblCMND.Visible = false;
            lblDC.Visible = false;
            lblDT.Visible = false;
            lblTenLK.Visible = false;
            txtTen.Visible = false;
            txtCMND.Visible = false;
            txtDienThoai.Visible = false;
            txtDiaChi.Visible = false;
            cbbTenLK.Visible = false;
            txtMa.Visible = true;
            cbbMaKT.Visible = true;
        }

        private void rdbNangCao_CheckedChanged(object sender, EventArgs e)
        {
            flag = 2;
            LoaiKhachBUS LKBUS = new LoaiKhachBUS();
            LoaiKhachDTO[] LK = new LoaiKhachDTO[100];
            LK = LKBUS.LayDSLoaiKhach();
            lblTenKT.Visible = true;
            lblCMND.Visible = true;
            lblDC.Visible = true;
            lblDT.Visible = true;
            lblTenLK.Visible = true;
            txtTen.Visible = true;
            txtCMND.Visible = true;
            txtDienThoai.Visible = true;
            txtDiaChi.Visible = true;
            cbbTenLK.Visible = true;
            cbbTenLK.ValueMember = "ID_LK";
            cbbTenLK.DisplayMember = "TenLK";
            cbbTenLK.DataSource = LK;
            txtMa.Visible = false;
            cbbMaKT.Visible = false;
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btnTim_Click(object sender, EventArgs e)
        {
            KhachThuePhongBUS ktBUS = new KhachThuePhongBUS();
            KhachThuePhongDTO kt = new KhachThuePhongDTO();
            KhachThuePhongDTO[] arr = new KhachThuePhongDTO[100];
            if (flag == 1)
            {
                kt.MaKT= Convert.ToInt32(cbbMaKT.SelectedValue);
                arr = ktBUS.TimKiemKhachThue(kt.MaKT);
                dtgvDSKT.DataSource = arr;
            }
            if (flag == 2)
            {
                kt.HoTen = txtTen.Text;
                kt.CMND_Passport = txtCMND.Text;
                kt.DienThoai = txtDienThoai.Text;
                kt.DiaChi = txtDiaChi.Text;
                kt.MaLK = Convert.ToInt32(cbbTenLK.SelectedValue);
                arr = ktBUS.TimKiemNangCao(kt);
                dtgvDSKT.DataSource = arr;
            }
        }

        private void frmTimKiemKhachThue_Load(object sender, EventArgs e)
        {
            KhachThuePhongDTO[] arr = new KhachThuePhongDTO[100];
            KhachThuePhongBUS ktBUS = new KhachThuePhongBUS();
            arr = ktBUS.LayDanhSachKT();
            cbbMaKT.ValueMember = "MaKT";
            cbbMaKT.DisplayMember = "MaKT";
            cbbMaKT.DataSource = arr;
        }
    }
}